package common;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class AnnotationUtils {

	
	public static Map<String,String> aaa( Class<? extends Annotation> annotationType )
	{
		Map result = new HashMap();
		int processedValuesFromDescriptor = 0;
		for (Method m : annotationType.getDeclaredMethods()) {
		    result.put(m.getName(), m.getDefaultValue() );
		}
		return result;
	}
	
	public static Map<String,String> fields(Annotation annotation)
	{
		Map<String,String> fields = new HashMap<>() ;
		
		if ( annotation != null && annotation.getClass()!=null )
		{
			String annotationStr = annotation.toString() ;
			String annotationFieldsStr = annotationStr.substring(annotationStr.indexOf("(")+1, annotationStr.indexOf(")"))  ;
			
			String[] fileds = annotationFieldsStr.split(",");
			for (String field : fileds) {
				String[] filedArr = field.trim().split("=") ;
				switch ( filedArr.length ) {
				case 1:
					fields.put(filedArr[0], null ) ;
					break;
				case 2:
					fields.put(filedArr[0], filedArr[1] ) ;
					break;
				default:
					break;
				}
			}
		}
		
		return fields ;
	}
}
